package com.cyt.web.controller.phone;

import com.cyt.work.question.model.po.Question;
import com.cyt.work.question.service.IQuestionService;
import com.cyt.work.site.model.vo.BannerVo;
import com.cyt.work.site.model.vo.NoticeVo;
import com.cyt.work.site.service.BannerService;
import com.cyt.work.site.service.NoticeService;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;

import javax.annotation.Resource;

/**
 * @author rong yuan
 * @date 2019/7/9 09:04
 */
@RestController
public class PhoneBaseController {

    @Resource
    private BannerService bannerService;
    @Resource
    private NoticeService noticeService;
    @Resource
    private IQuestionService questionService;

    /**
     * 跳转首页
     *
     * @param token   用户信息
     * @param applyId 应用ID
     * @return ModelAndView
     * @author rong yuan
     * @date 2019/7/9 09:08
     */
    @RequestMapping(value = "/phone/index", method = RequestMethod.GET)
    public ModelAndView index(String token, String applyId) {
        ModelAndView modelAndView = new ModelAndView();
        modelAndView.setViewName("/mobile/index");
        modelAndView.addObject("token", token);
        modelAndView.addObject("applyId", applyId);
        //首页轮播图
        BannerVo bannerVo = new BannerVo();
        bannerVo.setApplyId(applyId);
        bannerVo.setBannerType(String.valueOf(1));
        bannerVo.setStatus(String.valueOf(1));
        modelAndView.addObject(bannerService.list(bannerVo));
        //通知公告
        NoticeVo noticeVo = new NoticeVo();
        noticeVo.setApplyId(applyId);
        noticeVo.setNoticeType(String.valueOf(1));
        noticeVo.setStatus(String.valueOf(1));
        modelAndView.addObject(noticeService.list(noticeVo));
        // 获取最新的一条问卷数据
        Question question = questionService.selectFirstQuestion(applyId);
        if (question != null) {
            modelAndView.addObject("questionTitle", question.getTitle());
        }
        return modelAndView;
    }
}
